﻿using System.Linq;
using Volo.Abp;

namespace Shared.Service.DataPermissions
{
    /// <summary>
    /// 数据权限范围
    /// </summary>
    public abstract class DataPermission<T, TDataPermission> : BaseDataPermissionState
        where TDataPermission : DataPermission<T, TDataPermission>
    {

        /// <summary>
        /// 
        /// </summary>
        public T[] Ids { get; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="state"></param>
        protected DataPermission(DataPermissionState state) : base(state)
        {

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="ids"></param>
        protected DataPermission(T[] ids)
            : this(DataPermissionState.Normal)
        {
            Ids = Check.NotNullOrEmpty(ids, nameof(ids)).ToArray();
        }

        /// <summary>
        /// 以当前数据权限为基础，产生一个新的数据权限，
        /// 考虑用户输入的权限 默认交集计算  TODO 带抽象出通用方法
        /// </summary>
        /// <param name="inputIds"></param>
        /// <param name="disableAs">DisableAs 处理方式</param>
        /// <returns></returns>
        public abstract TDataPermission GetInputDataPermission(T[] inputIds, DisableAs disableAs = DisableAs.All);
    }
}
